package com.xyz.study.java.generic;

/**
 * 泛型 - 类型擦除，桥方法
 */
public class GenericErasure {
    // 擦除前
    public class Node<T> {

        public T data;

        public Node(T data) { this.data = data; }

        public void setData(T data) {
            System.out.println("Node.setData");
            this.data = data;
        }
    }

    public class MyNode extends Node<Integer> {
        public MyNode(Integer data) { super(data); }

        public void setData(Integer data) {
            System.out.println("MyNode.setData");
            super.setData(data);
        }
    }

    // 擦除后 （类名的后缀数字1为了区分，忽略）
    public class MyNode1 extends Node1 {
        public MyNode1(Integer data) { super(data); }

        // 编译器生成的桥方法
        public void setData(Object data) {
            setData((Integer) data);
        }

        public void setData(Integer data) {
            System.out.println("MyNode.setData");
            super.setData(data);
        }
    }


    public class Node1 {

        public Object data;

        public Node1(Object data) { this.data = data; }

        public void setData(Object data) {
            System.out.println("Node.setData");
            this.data = data;
        }
    }

    public static void main(String[] args) {
    }
}
